// posts/common/video-copy/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    img: {
      type: Object,
      value: {}
    },
    height_data: {
      type: String,
      value: '400rpx'
    },
    width_data: {
      type: String,
      value: '275rpx'
    },
    loop: { // 是否自动播放
      type: Boolean,
      value: true
    },
    video_url: { // 视频路径
      type: String,
      value: ''
    },
    video_pic: { // 默认图片
      type: String,
      value: ''
    },
    title: { // 标题
      type: String,
      value: ''
    },
    fit: {
      type: String,
      value: 'cover'
    },
    topStop: {// 离开顶部距离停止自动播放
      type: Number,
      value: 20
    },
    bottomStop: { // 据顶部距离停止自动播放
      type: Number,
      value: 20
    }
  },
  ready: function () {
    /** 监控视频是否需要播放 */
    //let {screenWidth, screenHeight} = this.extData.systemInfo //获取屏幕高度
    var  screenHeight = wx.getSystemInfoSync().windowHeight
    let topBottomPadding = screenHeight * this.properties.bottomStop / 100;
    let topTopPadding = screenHeight * this.properties.topStop / 100;
    const videoObserve = this.createIntersectionObserver()
    var context = wx.createVideoContext('video_show',this)
    videoObserve.relativeToViewport({bottom: -topBottomPadding, top: -topTopPadding})
        .observe(`#video_show`, (res) => { 
            let {intersectionRatio} = res
            if(intersectionRatio === 0) {
                //离开视界，因为视窗占比为0，停止播放
                context.pause()
            }else{
                context.play()
            }
        })
  },
  /**
   * 组件的初始数据
   */
  data: {
    video_id: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {

  }
})
